package com.sunbird.crm.servce.impl;

import com.sunbird.crm.entity.sys.TRole;
import com.sunbird.crm.entity.sys.TUserRole;
import com.sunbird.crm.servce.SysRoleService;
import com.sunbird.crm.dao.sys.TMeunMapper;
import com.sunbird.crm.dao.sys.TRolePermissionMapper;
import com.sunbird.crm.dao.sys.TUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @ClassName SysPerssionService
 * @Descriptiom TODO
 * @Author Sunbird
 * @Date 2019/8/21 16:50
 * @Version 1.0
 **/
@Service
public class SysPerssionService implements SysRoleService {

    @Autowired
    private TUserRoleMapper tUserRoleMapper;

    @Autowired
    private TRolePermissionMapper rolePermissionMapper;

    @Autowired
    private TMeunMapper meunMapper;
    /**
     * @Author Sunbird
     * @Description 根据用户名查询用户权限
     * @Date   2019/8/21
     * @Param
     * @return
     **/
    @Override
    public Set<String> findRoleNameByUserId(String userCode) {
        //根据用户查询角色id
        List<String> roles =tUserRoleMapper.selectByUserCode(userCode);
        //根据角色id 查询角色权限

        Set<String> perssions =new HashSet<String>();
//        roles.forEach(role ->{
           /*根据角色查询菜单id  */
            List<String> permissIds=rolePermissionMapper.selectByRoleid(roles);
//            TRole tRole = toVO(role);
//        });
        /* 查询菜单的权限*/
        return   meunMapper.selectByMuenId(permissIds);
    }

    @Override
    public TRole findRoleNameByRoleId(Integer roleid) {
        return null;
    }

    private TRole toVO(TUserRole role){
        TRole  trole = new TRole();
//        trole.setRoleId(role.get());
//        trole.setRoleName(role.getRoleName());
//        trole.setCreateBy(role.getCreateBy());
//        trole.setPermission();
        return trole;
    }
}
